$(function () {
  BadRanking();
  CIndex();
  $("select,input").change(function(){
      BadRanking();
    CIndex();
  })
});


function BadRanking() {
  let myChart = echarts.init(document.getElementById("badRanking"));
  myChart.setOption({
    title: {
      text: "不良信用 Top5排行",
      left: 25,
      top: 25,
      textStyle: {
        fontSize: 15
      }
    },
    tooltip: {
      trigger: "item",
      formatter: "不良信用认定次数：{c}次"
    },
    grid: {
      left: 30,
      top: 65,
      right: 30,
      bottom: 40,
      containLabel: true
    },
    xAxis: {
      show: true,
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: {
        color: "#999",
        formatter: "{value}次"
      },
      splitLine: {
        lineStyle: {
          type: "dashed",
          color: "#eeeeee"
        }
      }
    },
    yAxis: {
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: "none",
      data: ["受到停工整改、通报批评或其他行政处理的", "申报信用信息时，故意隐瞒有关情况、提供虚假资料，或者以不正当手段影响评价结果客观真实的", "受到其他行政处罚的", "受到停工整改、通报批评或其他行政处理的", "利用虚假材料、以欺骗手段取得企业资质的"]
    },
    series: [
      {
        type: 'bar',
        barWidth: 12,
        itemStyle: {
          color: '#F6AB2E',
          barBorderRadius: 2,
          emphasis: {
            color: '#F6AB2E',
          },
        },
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: [0, -20],
            textStyle: {
              fontSize: 14
            },
            formatter: function (data) {
              return data.name;
            },
          }
        },
        data: [11, 23, 36, 46, 53],
        z: 2
      },
      {
        type: 'scatter',
        hoverAnimation: false,
        label: {
          color: "#F6AB2E",
          show: true,
          position: "right",
          padding: [0, 0, -2, -7],
          textStyle: {
            fontSize: 14,
          },
          formatter: function (param) {
            return param.value;
          },
        },
        itemStyle: {
          color: "transparent"
        },
        data: [11, 23, 36, 46, 53],
        z: 2,
      }
    ]
  });
  $("#badRanking").find('.collection_btn').remove();
  $("#badRanking").append("<a class='collection_btn' href='javascript:;'>查看详情 →</a>")
  $(window).resize(myChart.resize);
}

function CIndex() {
  let data = [
    {name: "受到其他行政处罚的XXXX", cog: "2", corr: "22"},
    {name: "受到其他行政处罚的PPPP", cog: "121", corr: "400"},
    {name: "受到其他行政处罚的ZZZZ", cog: "34", corr: "211"},
    {name: "受到其他行政处罚的OOOO", cog: "103", corr: "385"},
    {name: "受到其他行政处罚的YYYY", cog: "52", corr: "109"},
    {name: "受到其他行政处罚的QQQQ", cog: "200", corr: "550"},
  ];
  let cogData = [], corrData = [], yData = [], flag = false;
  data.sort(function (a, b) {
    return a.corr - b.corr
  });
  data.forEach(function (item) {
    cogData.push(item.cog);
    corrData.push(item.corr);
    yData.push(item.name);
  });
  if (data.length > 5) {
    flag = true
  }
  let myChart = echarts.init(document.getElementById("cIndex"));
  myChart.setOption({
    title: {
      text: "C级信用指标认定次数",
      left: 25,
      top: 20,
      textStyle: {
        fontSize: 15
      }
    },
    tooltip: {
      show: true,
      trigger: "item",
      formatter: function (params) {
        if (params.seriesIndex === 0) {
          return params.seriesName + "：" + params.value + "次"
        }
        if (params.seriesIndex === 2) {
          return params.seriesName + "：" + params.value + "家"
        }
      }
    },
    legend: {
      data: ["认定次数", "对应企业数"],
      right: 40,
      top: 20,
      icon: "circle",
      itemWidth: 10,
      itemHeight: 10,
      itemGap: 25,
      selectedMode: false,
      textStyle: {
        fontSize: 15,
        padding: [0, 0, -3]
      }
    },
    grid: {
      left: 30,
      top: 65,
      right: 40,
      bottom: 40,
      containLabel: true
    },
    dataZoom: [{
      type: "slider",
      show: flag,
      yAxisIndex: 0,
      endValue: 4,
      startValue: 0,
      handleIcon: "path://M959.846 509.535c0 247.319-200.527 447.846-447.846 447.846l0 0c-247.378 0-447.846-200.527-447.846-447.846l0 0c0-247.319 200.467-447.846 447.846-447.846l0 0c247.319 0 447.846 200.527 447.846 447.846l0 0z",
      handleSize: 8,
      handleStyle: {
        color: "#EAEDF3"
      },
      realtime: false,
      right: 0,
      width: 8,
      showDetail: false,
      showDataShadow: false,
      zoomLock: true,
      animate: false,
      backgroundColor: "transparent",
      borderColor: "transparent",
      fillerColor: "#EAEDF3",
    }],
    xAxis: {
      show: true,
      boundaryGap: [0, "5%"],
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: 'none',
      splitLine: {
        lineStyle: {
          type: "dashed",
          color: "#eeeeee"
        }
      }
    },
    yAxis: {
      axisTick: 'none',
      axisLine: 'none',
      axisLabel: "none",
      data: yData
    },
    series: [
      {
        name: "认定次数",
        type: 'bar',
        barWidth: 12,
        itemStyle: {
          color: '#1665D8',
          barBorderRadius: 2,
          emphasis: {
            color: '#1665D8',
          }
        },
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: [0, -20],
            textStyle: {
              fontSize: 14
            },
            formatter: function (data) {
              return data.name;
            },
          }
        },
        data: corrData,
        z: 2
      },
      {
        type: 'scatter',
        hoverAnimation: false,
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: [0, -20],
            textStyle: {
              fontSize: 14
            },
            formatter: function (data) {
              return data.name;
            },
          }
        },
        label: {
          color: "#1665D8",
          show: true,
          position: "right",
          padding: [0, 0, 12, -7],
          textStyle: {
            fontSize: 14,
          },
          formatter: function (param) {
            return param.value + "次";
          },
        },
        itemStyle: {
          color: "transparent"
        },
        data: corrData,
        z: 2,
      },
      {
        name: "对应企业数",
        type: 'bar',
        barWidth: 12,
        itemStyle: {
          color: '#EAECEE',
          barBorderRadius: 2,
          emphasis: {
            color: '#EAECEE',
          }
        },
        label: {
          normal: {
            color: "#999999",
            show: true,
            position: "right",
            padding: [0, 0, -3, -2],
            textStyle: {
              fontSize: 14,
            },
            formatter: function (data) {
              return data.value + "家";
            },
          }
        },
        data: cogData,
        z: 2
      },
    ]
  });
  $(window).resize(myChart.resize);
}
